package com.lyj.controller;

import com.lyj.pojo.Payment;
import com.lyj.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
public class PaymentController {

    @Autowired
    PaymentService paymentService;

    @RequestMapping("/queryAllPayment")
    @ResponseBody
    public List<Payment> queryAllPayment(){
        List<Payment> paymentList = paymentService.queryAllPayment();
        return  paymentList;
    }

    @RequestMapping("/queryPaymentByName")
    @ResponseBody
    public List<Payment> queryPaymentByName(String oldName){
        List<Payment> paymentList = paymentService.queryPaymentByName(oldName);
        return paymentList;

    }
//增加缴费信息
    @RequestMapping("/addPayment")
    @ResponseBody
    public Boolean addPayment(int oldId,String oldName,String admissionFee,String deductionFee,
                              String actualCost,String payMonth,String paymentStatus,String remarks) throws ParseException {

        Payment payment = new Payment();
        payment.setOldId(oldId);
        payment.setOldName(oldName);
        payment.setAdmissionFee(Double.valueOf(admissionFee.toString()));
        payment.setDeductionFee(Double.valueOf(deductionFee.toString()));
        payment.setActualCost(Double.valueOf(actualCost.toString()));
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = format.parse(payMonth+1);
        payment.setPayMonth(date);
        payment.setPaymentStatus(paymentStatus);
        payment.setRemarks(remarks);
        Boolean aBoolean = paymentService.addPayment(payment);
        return aBoolean;

    }
    //更新缴费信息
    @RequestMapping("/updatePayment")
    @ResponseBody
    public Boolean updatePayment(Payment payment){

        Boolean aBoolean = paymentService.updatePayment(payment);
        return aBoolean;
    }
    //删除
    @RequestMapping("/delPayment")
    @ResponseBody
    public Boolean delPayment(int paymentId){

        Boolean aBoolean = paymentService.delPayment(paymentId);
        return aBoolean;
    }




}
